package joc.contract;

import java.lang.annotation.Annotation;

import joc.customize.Contract;
import joc.customize.ForFieldEvaluateAtBeginningOfAllMethods;
import joc.customize.ForFieldEvaluateAtEndOfAllBehaviors;
import joc.customize.ForMethodEvaluateAtEndOfMethodAndInherit;
import joc.customize.ForParameterEvaluateAtBeginningOfBehavior;

public class ContainsStringContract implements Contract {
	@Override
	public Class<? extends Annotation> getAnnotationClass() {
		return ContainsString.class;
	}

	@ForFieldEvaluateAtBeginningOfAllMethods
	@ForFieldEvaluateAtEndOfAllBehaviors
	@ForParameterEvaluateAtBeginningOfBehavior
	@ForMethodEvaluateAtEndOfMethodAndInherit
	public boolean checkContract(ContainsString annotation, String value) {
		for (String part : annotation.value()) {
			if (!value.contains(part)) {
				return false;
			}
		}
		return true;
	}

}
